package com.exam.controller;

import com.exam.dto.ActionResult;
import com.exam.service.AnswerService;
import com.exam.vo.AnswerVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName TeacherAnswerController
 * @Description TODO
 * @action luoliang
 * @Data 2021/1/13 10:53
 * @Version 1.0
 */
@RestController
public class TeacherAnswerController {

    @Autowired
    private AnswerService answerService;
    @ApiOperation(value = "分页查询题库信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "查询的页码", required = true),
            @ApiImplicitParam(name = "size", value = "页面数据容量", required = true)
    })
    @RequestMapping(value = "/api/answers/{current}/{size}",method = RequestMethod.GET)
    @ResponseBody
    public ActionResult FindteacherBypage(@PathVariable Integer current, @PathVariable Integer size){
//         三表总记录数
        int countjudge = answerService.countByJudgeQuestion();
        int countfill = answerService.countByFillQuestion();
        int countmulti= answerService.countByMultiQuestion();
        int total = countjudge+countfill+countmulti;



        List<AnswerVO> list = answerService.findteacherAnswerByPage(current, size);
        HashMap<Object, Object> map = new HashMap<>();

        map.put("total",total);
        map.put("data",list);

        if (map != null){
            ActionResult success = new ActionResult(200, "success", map);
            return success;
        }else {
            ActionResult error = new ActionResult(203, "error", null);
            return error;
        }
    }
}
